


class Calc(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
<<<<<<< HEAD
        self.x = None
        self.y = None
        self.result = None
        self.operator = None
        self.equal = None
        self.clear = None
=======
<<<<<<< HEAD
>>>>>>> f4ae046c3f28468b10370b844c3d5de8e680a1f1
        uic.loadUi('calc.ui',self)
        btns = [self.pushButton0,
        self.pushButton1,
        self.pushButton2,
        self.pushButton3,
        self.pushButton4,
        self.pushButton5,
        self.pushButton6,
        self.pushButton7,
        self.pushButton8,
        self.pushButton9,
        self.pushButton_clear,
        self.pushButton_add,
        self.pushButton_sub,
        self.pushButton_div,
        self.pushButton_mul,
        self.pushButton_dot,
        self.pushButton_equal]

        map(lambda btn:btn.clicked.connect(self.click_on_button),btns)
    def calculate(self):
        """
        如果x,y,operator不为空，计算结果

        """
        if self.x and self.y and self.operator:
            self.result = str(eval("%s%s%s"%(self.x,self.operator,self.y)))
            self.text_result.setText(self.result)
    def click_on_button(self):
        print self.sender().text()


if __name__ == '__main__':    
=======
        self.x = None
        self.y = None
        self.result = None
        self.operator = None
        self.equal = None
        self.clear = None
        uic.loadUi('calc.ui', self)
        btns = [self.pushButton0,
                self.pushButton2,
                self.pushButton3,
                self.pushButton4,
                self.pushButton5,
                self.pushButton6,
                self.pushButton7,
                self.pushButton8,
                self.pushButton9,
                self.pushButton1,
                self.pushButton_add,
                self.pushButton_sub,
                self.pushButton_mul,
                self.pushButton_div,
                self.pushButton_dot,
                self.pushButton_clear,
                self.pushButton_equal]
    
        map(lambda btn: btn.clicked.connect(self.click_on_button), btns)

    def click_on_button(self):
        print self.sender().text()

    def calculate(self):
        """
        如果x,y,operator不为空，计算结果
        """
        if self.x and self.y and self.operator:
            self.result = str(eval("%s%s%s"%(self.x,self.y,self.operator)))
            self.text_result.setText(self.result)

if __name__ == '__main__':
>>>>>>> fa9f91976ad9f001519ee1dabf802c54fc83fac7
    app = QApplication(sys.argv)
    # print help(QApplication)
    calc = Calc()
    calc.x = '4'
    calc.y = '2'
    calc.operator = '/'
    calc.calculate()

    calc.show()
    calc.x = '1'
    calc.y = '2'
    calc.operator = ''
    calc.calculate()
    app.exec_()
